package com.example.androidproject.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatImageView;

import com.example.androidproject.widget.interfaces.OnPressCallback;
import com.example.androidproject.widget.interfaces.OnSingleOrLongClickCallback;

/**
 * FileName: LongPressImageView
 * Author: huangyuguang
 * Date: 2022/6/30
 * Description: 长按事件处理
 */
public class LongPressImageView extends AppCompatImageView {

    private OnPressCallback onPressCallback;

    public LongPressImageView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public void setOnPressCallback(OnPressCallback onPressCallback) {
        this.onPressCallback = onPressCallback;
        OnSingleOrLongClickCallback singleOrLockClickCallback = new OnSingleOrLongClickCallback() {
            @Override
            public void callback(@org.jetbrains.annotations.Nullable View view, boolean isStop) {
                if(onPressCallback != null){
                    onPressCallback.pressCallback(view,isStop);
                }
            }
        };
        singleOrLockClickCallback.setView(this);
        singleOrLockClickCallback.init();
    }

}
